/* pmenu.c */

#include "pmenu.h"

unsigned int pmenu_text_center(char * label, TTF_Font * font, SDL_Color color, unsigned int y, SDL_Surface * target)
{
	SDL_Surface * temp_surface;
	SDL_Rect destination;
	unsigned int ret = 0;
	int size_x = 0, size_y = 0;
	TTF_SizeText(font, label, &size_x, &size_y);
	destination.x = target->w / 2 - size_x / 2;
	destination.y = y;
	destination.w = size_x;
	destination.h = size_y;
	temp_surface = TTF_RenderText_Blended(font, label, color);
	SDL_BlitSurface(temp_surface, NULL, target, &destination);
	SDL_FreeSurface(temp_surface);
	return ret;
}

void pmenu_wait_for_any_key(void)
{
	unsigned int quit = 0;
	SDL_Event pmenu_event;
	while(!quit)
	{
		if (SDL_PollEvent(&pmenu_event))
		{
			if (pmenu_event.type == SDL_KEYDOWN)
			{
				quit = 1;
			}
		}
		SDL_Delay(TimeLeft());
	}
	quit = 0;
	while(!quit)
	{
		if (SDL_PollEvent(&pmenu_event))
		{
			if (pmenu_event.type == SDL_KEYUP)
			{
				quit = 1;
			}
		}
		SDL_Delay(TimeLeft());
	}
}

